<html><head><title>VertexAnimation.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - VertexAnimation
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">; shapekey.mesh + shapekey.material done by blendman, thanks :)
</font>
<font color="#3A3966">;Use [PageUp] and [PageDown]
</font>
<b><font color="#3A3966">IncludeFile</font></b> <font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Screen3DRequester.pb&quot;

<b><font color="#3A3966">Define</font></b>.f MouseX, MouseY, Pose 

<font color="#924B72">#Mesh</font> = 1

<b><font color="#3A3966">Macro</font></b> <font color="#3A3966">Clamp</font>(num, min, max)
  <b><font color="#3A3966">If</font></b> num&lt;min
    num=min
  <b><font color="#3A3966">ElseIf</font></b> num&gt;max
    num=max
  <b><font color="#3A3966">EndIf</font></b>  
<b><font color="#3A3966">EndMacro</font></b>

<b><font color="#3A3966">If</font></b> <font color="#3A3966">InitEngine3D</font>(3)
    
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Textures&quot;, <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Models&quot;, <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Scripts&quot;, <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#3A3966">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + &quot;examples/3d/Data/Packs/desert.zip&quot;, <font color="#924B72">#PB_3DArchive_Zip</font>)
<font color="#3A3966">  Parse3DScripts</font>()
  
<font color="#3A3966">  InitSprite</font>()
<font color="#3A3966">  InitKeyboard</font>()
<font color="#3A3966">  InitMouse</font>()
  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">Screen3DRequester</font>()
    
<font color="#3A3966">    WorldShadows</font>(<font color="#924B72">#PB_Shadow_Modulative</font>)
    
    <font color="#3A3966">;Ground
</font>    <font color="#3A3966">;
</font><font color="#3A3966">    CreateMaterial</font>(0,<font color="#3A3966"> LoadTexture</font>(0, &quot;Dirt.jpg&quot;))
<font color="#3A3966">    CreatePlane</font>(0, 1500, 1500, 40, 40, 15, 15)
<font color="#3A3966">    CreateEntity</font>(0,<font color="#3A3966">MeshID</font>(0),<font color="#3A3966">MaterialID</font>(0))
    
    <font color="#3A3966">;- Mesh
</font>    
<font color="#3A3966">    LoadMesh</font>(<font color="#924B72">#Mesh</font>, &quot;Shapekey.mesh&quot;)
    
    <font color="#3A3966">; Create a animation state For each vertex pose, using the pose name 
</font>    Track     = 0 
    KeyFrame  = 0 
    PoseIndex = 0
    Animation$ =<font color="#3A3966"> MeshPoseName</font>(<font color="#924B72">#Mesh</font>, PoseIndex)
    
<font color="#3A3966">    CreateVertexAnimation</font>(<font color="#924B72">#Mesh</font>, Animation$, 0)                 <font color="#3A3966">; Create animation just for this pose
</font><font color="#3A3966">    CreateVertexTrack</font>(<font color="#924B72">#Mesh</font>, Animation$, Track)                 <font color="#3A3966">; Create track for this pose
</font><font color="#3A3966">    CreateVertexPoseKeyFrame</font>(<font color="#924B72">#Mesh</font>, Animation$, Track, KeyFrame)<font color="#3A3966">; Create a keyframe for this pose.
</font>        
    <font color="#3A3966">;- Entity
</font><font color="#3A3966">    CreateEntity</font>(1,<font color="#3A3966"> MeshID</font>(<font color="#924B72">#Mesh</font>), <font color="#924B72">#PB_Material_None</font>, 0, 50, 0)
<font color="#3A3966">    ScaleEntity</font>(1, 3, 3, 3)
<font color="#3A3966">    StartEntityAnimation</font>(1, Animation$)  
   
    <font color="#3A3966">;- SkyBox
</font><font color="#3A3966">    SkyBox</font>(&quot;Desert07.jpg&quot;)
    
    <font color="#3A3966">;- Camera
</font><font color="#3A3966">    CreateCamera</font>(0, 0, 0, 100, 100)
<font color="#3A3966">    MoveCamera</font>(0, 10,<font color="#3A3966"> EntityY</font>(1) + 4, -10, <font color="#924B72">#PB_Absolute</font>)
<font color="#3A3966">    CameraLookAt</font>(0,<font color="#3A3966"> EntityX</font>(1),<font color="#3A3966"> EntityY</font>(1),<font color="#3A3966"> EntityZ</font>(1))
    
    <font color="#3A3966">;- Light
</font><font color="#3A3966">    CreateLight</font>(0,<font color="#3A3966"> RGB</font>(255, 255, 255), -40, 100, 80)
<font color="#3A3966">    AmbientColor</font>(<font color="#3A3966">RGB</font>(80, 80, 80))
     
    <b><font color="#3A3966">Repeat</font></b>
<font color="#3A3966">      Screen3DEvents</font>()
      
      <b><font color="#3A3966">If</font></b> <font color="#3A3966">ExamineMouse</font>()
        MouseX = -<font color="#3A3966">MouseDeltaX</font>()/10 
        MouseY = -<font color="#3A3966">MouseDeltaY</font>()/10
      <b><font color="#3A3966">EndIf</font></b>
      
      <b><font color="#3A3966">If</font></b> <font color="#3A3966">ExamineKeyboard</font>()
        
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_PageDown</font>) <b><font color="#3A3966">And</font></b> Pose &lt; 1
          Pose + 0.01
<font color="#3A3966">          Clamp</font>(Pose, 0, 1)
        <b><font color="#3A3966">ElseIf</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_PageUp</font>) <b><font color="#3A3966">And</font></b> Pose &gt; 0
          Pose - 0.01
<font color="#3A3966">          Clamp</font>(Pose, 0, 1) 
        <b><font color="#3A3966">EndIf</font></b>
        
      <b><font color="#3A3966">EndIf</font></b>
      
      <font color="#3A3966">; update the pose reference
</font><font color="#3A3966">      UpdateVertexPoseReference</font>(<font color="#924B72">#Mesh</font>, Animation$, Track, KeyFrame, PoseIndex, Pose)
      
      <font color="#3A3966">; update animation state since we're fudging this manually
</font><font color="#3A3966">      UpdateEntityAnimation</font>(1, Animation$)
      
<font color="#3A3966">      RotateCamera</font>(0, MouseY, MouseX, 0, <font color="#924B72">#PB_Relative</font>)
      
<font color="#3A3966">      RenderWorld</font>() 
      
<font color="#3A3966">      FlipBuffers</font>()
    <b><font color="#3A3966">Until</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>) <b><font color="#3A3966">Or</font></b> Quit = 1
  <b><font color="#3A3966">EndIf</font></b>
  
<b><font color="#3A3966">Else</font></b>
<font color="#3A3966">  MessageRequester</font>(&quot;Error&quot;, &quot;The 3D Engine can't be initialized&quot;,0)
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">End</font></b></font></pre>
</body></html>
